home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1994 October / Macformat17.cdr / Shareware City / Developers / shutdown-fx-201-c / sfx ƒ / sfx control app ƒ / sfx code ƒ / pixel dissolve.c < prev    next >
Text File  |  1994-07-11  |  3KB  |  122 lines

  1. /**********************************************************************\
  2.  
  3. File:        pixel dissolve.c
  4.  
  5. Purpose:    Graphic effect to copy offscreen grafptr to onscreen window.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program in a file named "GNU General Public License".
  19. If not, write to the Free Software Foundation, 675 Mass Ave,
  20. Cambridge, MA 02139, USA.
  21.  
  22. \**********************************************************************/
  23.  
  24. #include "pixel dissolve.h"
  25. #include "timing.h"
  26.  
  27. #define SUB_HEIGHT 25
  28. #define SUB_WIDTH 25
  29. #define POINT_SIZE 1
  30.  
  31. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  32. #define theWindowWidth (boundsRect.right-boundsRect.left)
  33. #define CorrectTime 1
  34.  
  35. static pascal unsigned long UniformRandomUL(unsigned long *theSeed);
  36.  
  37. pascal short PixelDissolve(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect)
  38. {
  39.     register long    row,col,r;
  40.     unsigned long    w, h;
  41.     Point            *ptptr;
  42.     unsigned long    iter, save_iter;
  43.     Rect            temp;
  44.     short            i,j;
  45.     register long    theValue;
  46.     unsigned long    theSeed;
  47.     
  48.     w=theWindowWidth;
  49.     h=theWindowHeight;
  50.     save_iter=iter=SUB_HEIGHT*SUB_WIDTH/(POINT_SIZE*POINT_SIZE);
  51.     ptptr=(Point*)NewPtr(sizeof(Point)*iter);
  52.     if (ptptr==0L)
  53.         return -1;
  54.     iter=0;
  55.     for (i=0; i<SUB_HEIGHT; i+=POINT_SIZE)
  56.     {
  57.         theValue=i;
  58.         theValue<<=16;
  59.         for (j=0; j<SUB_WIDTH; j+=POINT_SIZE)
  60.         {
  61.             ((long*)ptptr)[iter++]=theValue;
  62.             theValue+=POINT_SIZE;
  63.         }
  64.     }
  65.     
  66.     GetDateTime(&theSeed);
  67.     
  68.     for (iter=1; iter<save_iter; iter++)
  69.     {
  70.         r=UniformRandomUL(&theSeed)%iter;
  71.         theValue=((long*)ptptr)[r];
  72.         ((long*)ptptr)[r]=((long*)ptptr)[iter];
  73.         ((long*)ptptr)[iter]=theValue;
  74.     }
  75.  
  76.     for (iter=0; iter<save_iter; iter++)
  77.     {
  78.         StartTiming();
  79.         temp.left=ptptr[iter].h;
  80.         temp.top=ptptr[iter].v;
  81.         temp.right=temp.left+POINT_SIZE;
  82.         temp.bottom=temp.top+POINT_SIZE;
  83.         for (row=0; row<h; row+=SUB_HEIGHT)
  84.         {
  85.             for (col=0; col<w; col+=SUB_WIDTH)
  86.             {
  87.                 CopyBits(&(sourceGrafPtr->portBits), &(destGrafPtr->portBits),
  88.                         &temp, &temp, 0, 0L);
  89.                 temp.left+=SUB_WIDTH;
  90.                 temp.right+=SUB_WIDTH;
  91.             }
  92.             temp.left-=col;
  93.             temp.right-=col;
  94.             temp.top+=SUB_HEIGHT;
  95.             temp.bottom+=SUB_HEIGHT;
  96.         }
  97.         TimeCorrection(CorrectTime);
  98.     }
  99.     
  100.     DisposePtr(ptptr);
  101.     
  102.     return 0;
  103. }
  104.  
  105. #define    M        1664525
  106. #define    C        1
  107. #define    LOW(X)    (X&0xFFFF)
  108. #define    HIGH(X)    ((X>>16)&0xFFFF)
  109.  
  110. pascal unsigned long UniformRandomUL(unsigned long *seed)
  111. {
  112.     unsigned long    lo, hi;
  113.     
  114.     lo=LOW(LOW(*seed)*LOW(M)+C);
  115.     hi=LOW(HIGH(*seed)*LOW(M))+LOW(HIGH(M)*LOW(*seed))+
  116.             HIGH(LOW(*seed)*LOW(M)+C);
  117.     
  118.     *seed=((hi<<16)|lo);
  119.     
  120.     return *seed;
  121. }
  122.